<template>
  <div>
    <h3>Count组件的求和为：{{sum}}</h3>
    <h3>列表中第一个人的名字是：{{firstPersonName}}</h3>
    <h3>人员信息</h3>
    <input v-model="name" type="text" placeholder="请输入名字" />
    <button @click="add">添加</button>
    <button @click="addWang">添加一个姓王的人</button>
    <button @click="addServer">添加一个人，名字随机</button>
    <ul>
      <li v-for="item in personsList" :key="item.id">{{ item.name }}</li>
    </ul>
  </div>
</template>

<script>
import { nanoid } from "nanoid";
// import { mapGetters, mapState } from "vuex";
export default {
  name: "Person",
  data() {
    return {
      name: "",
    };
  },
  components: {},
  computed: {
    // ...mapState({ personsList: "personsList" }),
    // ...mapState({ sum: "sum" }),
    sum() {
        return this.$store.state.countAbout.sum
    },
    personsList() {
        return this.$store.state.personAbout.personsList
    },
    firstPersonName() {
        return this.$store.getters["personAbout/firstPersonName"]
    }
    // ...mapGetters("personAbout",['personsList'])
  },
  mounted() {},
  methods: {
    add() {
      const personObj = { id: nanoid(), name: this.name };
      this.$store.commit("personAbout/ADD_PERSON", personObj);
      console.log(personObj);
    },
    addWang() {
      const personObj = { id: nanoid(), name: this.name };
      this.$store.dispatch("personAbout/addPersonWang", personObj);
    },
    addServer() {
      this.$store.dispatch("personAbout/addPersever");
    }
  },
};
</script>

<style scoped>
</style>
